/**
 * Created by ajhin on 7/11/2015.
 */
package com.societyGames2.convert
{
import org.as3commons.asblocks.parser.antlr.LinkedListTree;

/**
 * Puts different separator after each child.
 */
public class MultipleFixedTreeConverter implements ITreeConverter
{
  private var _separators:Array;
  private var _index:int;

  public function MultipleFixedTreeConverter(...args:Array)
  {
    _separators = args;
  }

  //ITreeToCSharp-->
  public function convert(tree:LinkedListTree):String
  {
    _index = 0;
    var source:String = getSeparator();
    for (var i:int = 0; tree.children != null && i < tree.children.length; i++)
    {
      var childTree:LinkedListTree = LinkedListTree(tree.getChild(i));
      source += TreeConverters.convert(childTree);
      source += getSeparator();
    }
    return source;
  }
  //<--ITreeToCSharp

  private function getSeparator():String
  {
    if (_index < _separators.length)
    {
      _index++;
      return _separators[_index - 1];
    }
    return "";
  }
}
}
